//
//  CZUserProtocolViewController.m
//  nsj_iOS
//
//  Created by apple on 2017/2/12.
//  Copyright © 2017年 GCZ. All rights reserved.
//

#import "CZUserProtocolViewController.h"

@interface CZUserProtocolViewController ()

@end

@implementation CZUserProtocolViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"那世界APP使用协议";
    self.automaticallyAdjustsScrollViewInsets = NO;
    UILabel *label = [[UILabel alloc] init];
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByCharWrapping;
    label.textColor = [UIColor grayColor];
    label.font = [UIFont systemFontOfSize:15];
    
    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"pro" ofType:@"txt" ];
    NSData *myData = [NSData dataWithContentsOfFile:filePath];
    NSString *text = [[NSString alloc] initWithData:myData encoding:(NSUTF8StringEncoding)];
    label.text = text;
    CGFloat height = [self heightForString:text fontsize:15];
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, Main_Screen_Width, Main_Screen_Height - 64)];
    label.frame = CGRectMake(20, 0, Main_Screen_Width  - 40, height);
    scrollView.contentSize = CGSizeMake(Main_Screen_Width, height);
    [self.view addSubview:scrollView];
    [scrollView addSubview:label];
    
    // Do any additional setup after loading the view from its nib.
}


- (CGFloat)heightForString:(NSString *)string fontsize:(NSInteger)fontsize {
    
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    
    NSDictionary *attributes = @{ NSFontAttributeName : [UIFont systemFontOfSize:fontsize], NSParagraphStyleAttributeName : style};
    
    
    CGRect bounds = [string boundingRectWithSize:CGSizeMake(Main_Screen_Width - 40, CGFLOAT_MAX) options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading) attributes:attributes context:nil];
    
    //3.返回bounds的高度
    if (bounds.size.height < 30) {
        return 30;
    } else {
        return bounds.size.height + 20;
    }
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
    self.navigationController.navigationBar.alpha = 1;
    
    [(UIView*)[self.navigationController.navigationBar.subviews objectAtIndex:0] setAlpha:1.f];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
